﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using QuizApp.Web;

namespace QuizApp.Views
{
    public partial class NovaQuestaoPage : Page
    {
        public NovaQuestaoPage()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void materiaDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        {

            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //var ctx = new QuizDomainContext();
            QuizDomainContext ctx = new QuizDomainContext();
            int? _idMateria, _idTopico, _idSubtopico, _idUsuario;
            _idMateria = (int?) nomeComboBox.SelectedValue;
            _idTopico = (int?)nomeComboBox1.SelectedValue;
            _idSubtopico = (int?)nomeComboBox2.SelectedValue;
            //idUsuario = nomeComboBox.SelectedValue;


            Web.QuestaoSimplesView newQuestion = new QuestaoSimplesView()
            {
                idMateria = _idMateria,
                idTopico = _idTopico,
                idSubTopico = _idSubtopico,
                idUsuario = null,
                Texto = textBox1.Text,
                Gabarito = (bool)checkBox1.IsChecked ? 1 : 0
            };
                            
            ctx.QuestaoSimplesViews.Add(newQuestion);
            ctx.SubmitChanges();
            
            
            //Web.No tmp = new Web.Materia() { Nome = textBox1.Text };
            //ctx.Materias.Add(tmp);
            //ctx.SubmitChanges();

        }

        private void materiaDomainDataSource1_LoadedData(object sender, LoadedDataEventArgs e)
        {

            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }

    }
}
